package com.huaxin.hxmoduleworkorder.models;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.huaxin.hxmoduleworkorder.common.StringListToJsonTypeHandler;
import com.huaxin.hxmoduleworkorder.common.enums.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;

@Data
@TableName(value = "maintenance_order", autoResultMap = true)
@EqualsAndHashCode(callSuper = true)
public class MaintenanceOrder extends BaseModel {
    @TableField(value = "type")
    @Schema(description = "工单类型：maintenance/inspection/install", example = "maintenance")
    private OrderType type;

    @TableField(value = "title")
    @Schema(description = "工单标题", example = "客户报修：配电箱跳闸")
    private String title;

    @TableField(value = "description")
    @Schema(description = "问题描述", example = "客户反映家中频繁跳闸")
    private String description;

    @TableField(value = "status")
    @Schema(description = "流程状态：created/reviewing/assigned/accepted/on_site/processing/resolved/evaluating/completed/rejected/cancelled", example = "assigned", defaultValue = "created")
    private MaintenanceOrderStatus status;

    @TableField(value = "priority")
    @Schema(description = "优先级：low/medium/high/urgent", example = "high")
    private MaintenanceOrderPriority priority;

    @TableField(value = "source_type")
    @Schema(description = "来源：customer/electrician/admin/inspection", example = "customer")
    private MaintenanceOrderSourceType sourceType;

    @TableField(value = "source_id")
    @Schema(description = "来源ID（如来自巡查工单或巡查项ID）", example = "ins_order_001")
    private String sourceId;

    @TableField(value = "customer_type")
    @Schema(description = "客户类型，允许值：residential（住宅）/industrial（工业）/commercial（商业）", example = "residential")
    private CustomerType customerType;

    @TableField(value = "customer_id")
    @Schema(description = "客户ID", example = "c1001")
    private String customerId;

    @TableField(value = "customer_name")
    @Schema(description = "客户姓名", example = "张三")
    private String customerName;

    @TableField(value = "equipment_id")
    @Schema(description = "关联设备ID（可选）", example = "eqp_001")
    private String equipmentId;

    @TableField(value = "contact_phone")
    @Schema(description = "客户联系电话", example = "13800138000")
    private String contactPhone;

    @TableField(value = "preferred_time", typeHandler = StringListToJsonTypeHandler.class)
    @Schema(description = "客户期望上门时间（时间段）", example = "[\"2025-09-02 09:00\",\"2025-09-02 12:00\"]")
    private List<String> preferredTime;

    @TableField(value = "address")
    @Schema(description = "客户地址", example = "北京市朝阳区XX路XX号")
    private String address;

    @TableField(value = "address_longitude")
    @Schema(description = "客户地址经度", example = "116.397128")
    private String addressLongitude;

    @TableField(value = "address_latitude")
    @Schema(description = "客户地址纬度", example = "39.915119")
    private String addressLatitude;

    @TableField(value = "electrician_id")
    @Schema(description = "电工ID", example = "electrician_001")
    private String electricianId;

    @TableField(value = "assign_at")
    @Schema(description = "分配时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime assignAt;

    @TableField(value = "reject_at")
    @Schema(description = "驳回时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime rejectAt;

    @TableField(value = "reject_reason")
    @Schema(description = "驳回原因", example = "信息不完整")
    private String rejectReason;

    @TableField(value = "cancel_at")
    @Schema(description = "取消时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime cancelAt;

    @TableField(value = "cancel_reason")
    @Schema(description = "取消原因", example = "信息不完整")
    private String cancelReason;

    @TableField(value = "resolve_at")
    @Schema(description = "解决时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime resolveAt;

    @TableField(value = "complete_at")
    @Schema(description = "完成时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime completeAt;

    @TableField(value = "created_by_role")
    @Schema(description = "创建人角色：customer/electrician/admin", example = "customer")
    private MaintenanceOrderOperatorRole createdByRole;
}

